package com.ming.transaction.controller;


import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.ming.transaction.common.Result;
import com.ming.transaction.exception.ServiceException;
import com.ming.transaction.service.IImageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 陈仕健
 * @since 2023-05-04
 */
@Api(tags = "图片控制器")
@RestController
@RequestMapping("/image")
public class ImageController {

    @Resource
    private IImageService imageService;

    @ApiOperation("图片上传接口")
    @PostMapping("/upload")
    public Result upload(@RequestParam MultipartFile file) throws IOException {
        return imageService.uploadImage(file);
    }

    @ApiOperation("图片获取接口")
    @GetMapping(value = "/{fileUUID}",produces = "image/jpeg")
    public void download(@PathVariable String fileUUID) throws IOException{
        imageService.dowmloadImage(fileUUID);
    }


}

